﻿using Phones.Client.Repository;
using Phones.Client.Model;

namespace Phones.Client.ViewModel
{
    public class DepartnemtTreeNodeViewModel: TreeViewItemBaseViewModel
    {

        private Department _department;

        public Department Model
        {
            get { return _department; }
        }

        public DepartnemtTreeNodeViewModel(OrganisationTreeNodeViewModel parent, Department dep)
            : base(parent, true)
        {
            _department = dep;
        }

        protected override void LoadChildren()
        {
            Children.Clear();

            using (var db = new ContactsRepository())
            {
                var list = db.GetList((Parent.Parent as ServiceNodeTreeNodeViewModel).Model, _department);

                foreach (var item in list)
                {
                    Children.Add(new ContactTreeNodeViewModel(this, item));
                }
            }
        }

    }
}
